import Vuex from 'vuex';
import Vue from 'vue';
import axios from 'axios';
import Qs from 'qs'
Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        a: true,
        arr:'',
        arrhostory:[]
    },
    getters: {
    },
    mutations: {
        fn1(state, payload) {
            console.log(payload)
            state.a = false
        },
        fn2(state, payload) {
            console.log(payload)
            state.a = false
        },
        changeArr(state,payload){
            state.arr = payload
        },
        changeArrhostory(state,payload){
            state.arrhostory.push(payload)
        },
        cleanhistory(state,payload){
            console.log(payload)
            state.arrhostory.splice(0)
        }
    },
    actions: {
        searchenter(store, payload) {
            console.log(store)
            if(store.state.arrhostory.indexOf(payload) == -1){
                store.commit('changeArrhostory',payload)
            }
              axios.post('/shengxian/m/molie/gettuanlist.php?page=1',Qs.stringify({keyword:payload})).then(function(data){
                    store.commit('changeArr',data.data.goods_list)
                })
        }
    }
})

export default store;